#include "home.h"
#include "ui_home.h"
#include <QMessageBox>
Home::Home(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Home) {
    qDebug()<<"Home::Home called.";
    ui->setupUi(this);
    /* TODO: [Done] 美化首页
     * 手段、效果不限
     * 效果举例: https://www.jianshu.com/p/3ba5b6fe7980
     */
    imgNum_Home=1;
    // ui->label_slide->setText("下一张");
    connect(ui->pushButton_next,SIGNAL(clicked()),this,SLOT(nextPic()));
    connect(ui->pushButton_previous,SIGNAL(clicked()),this,SLOT(prevPic()));
    ui->label_slide->setScaledContents(true);
    qTimer=new QTimer();
    connect(this->qTimer,SIGNAL(timeout()),this,SLOT(nextPic()));
    qTimer->start(3000);
    qDebug()<<"Home::Home returned.";
}

Home::~Home() {
    qDebug()<<"Home::~Home called.";
    delete ui;
    qDebug()<<"Home::~Home returned.";
}

void Home::nextPic() {
//    qDebug()<<"Home::nextPic call.";
    ++imgNum_Home;
    showPictureSlot();
//    qDebug()<<"Home::nextPic return.";
}

void Home::prevPic() {
//    qDebug()<<"Home::prevPic call.";
    imgNum_Home--;
    if(imgNum_Home<=0)
        imgNum_Home+=5;
    showPictureSlot();
//    qDebug()<<"Home::prevPic return.";
}

void Home::showPictureSlot() {
//    qDebug()<<"Home::showPictureSlot call.";
    if(!this->isVisible()) {
        ui->label_slide->clear();
        return;
    }
    QString path=":/slide/images/slide/"+QString::number(imgNum_Home)+".jpg";
    QPixmap pixmap(path);
    pixmap=pixmap.scaled(ui->label_slide->size(),Qt::KeepAspectRatio);
    ui->label_slide->setPixmap(pixmap);
    imgNum_Home=imgNum_Home%5;
//    qDebug()<<"Home::showPictureSlot return.";
}
